/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.Draw.Entities.Impl;

import Model.Core.Impl.State;
import Model.Draw.Coordinate;
import Model.Draw.Line;
import Model.Draw.Point;

/**
 *
 * @author Mih
 */
public class StateLine extends Line{
    private StateJoint joint;
    private State parentState;
    
    public StateLine(Point source, Point target, State parentState){
        super(source, target);
        this.parentState = parentState;
        joint = new StateJoint(new Coordinate((getExtreamSourcePoint().getX().getCoordinate() + getExtreamTargetPoint().getX().getCoordinate()) / 2), new Coordinate((getExtreamSourcePoint().getY().getCoordinate() + getExtreamTargetPoint().getY().getCoordinate()) / 2), this.parentState);
    }
    
    public Point getMoreLeftPoint(){
        double x = 0;
        double y = 0;
        if(getExtreamSourcePoint().getX().getCoordinate() < getExtreamTargetPoint().getX().getCoordinate())
            x = getExtreamSourcePoint().getX().getCoordinate();
        else
            x = getExtreamTargetPoint().getX().getCoordinate();
        if(getExtreamSourcePoint().getY().getCoordinate() < getExtreamTargetPoint().getY().getCoordinate())
            y = getExtreamSourcePoint().getY().getCoordinate();
        else
            y = getExtreamTargetPoint().getY().getCoordinate();
        return new Point(new Coordinate(x), new Coordinate(y));
    }

    public void AddLinkPoint(Point linkPoint)
    {
        joint.setLinkPoint(linkPoint);
    }
    /**
     * @return the point joint
     */
    public StateJoint getJoint() {
        //TODO: update Joint coordinates
        return joint;
    }
    
    public void move(int diffX, int diffY){
        setExtreamTargetPoint(new Point(new Coordinate(getExtreamTargetPoint().getX().getCoordinate() + diffX), new Coordinate(getExtreamTargetPoint().getY().getCoordinate() + diffY)));
        setExtreamSourcePoint(new Point(new Coordinate(getExtreamSourcePoint().getX().getCoordinate() + diffX), new Coordinate(getExtreamSourcePoint().getY().getCoordinate() + diffY)));
        joint = new StateJoint(new Coordinate((getExtreamSourcePoint().getX().getCoordinate() + getExtreamTargetPoint().getX().getCoordinate()) / 2), new Coordinate((getExtreamSourcePoint().getY().getCoordinate() + getExtreamTargetPoint().getY().getCoordinate()) / 2), this.parentState);
    }
}
